{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](https://github.com/callysto/callysto-sample-notebooks/blob/master/notebooks/images/Callysto_Notebook-Banner_Top_06.06.18.jpg?raw=true)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calendar Algorithm for any date in the 20th or 21st century\n",
    "## Note that January 1, 1901 was Tuesday and January 1, 2001 was Monday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calculate_day(year,month,day): \n",
    "    \n",
    "    if month==1: shift=0\n",
    "    elif month==2: shift=3\n",
    "    elif month==3: shift=3\n",
    "    elif month==4: shift=6\n",
    "    elif month==5: shift=1\n",
    "    elif month==6: shift=4\n",
    "    elif month==7: shift=6\n",
    "    elif month==8: shift=2\n",
    "    elif month==9: shift=5\n",
    "    elif month==10: shift=0\n",
    "    elif month==11: shift=3\n",
    "    elif month==12: shift=5\n",
    "    else: return \"ERROR\" \n",
    "        \n",
    "    mytotal=(year-1900) + (year-1900)//4 + day + shift\n",
    "    \n",
    "    if month<=2 and year%4==0: mytotal=mytotal-1\n",
    "    \n",
    "    remainder = mytotal % 7\n",
    "    \n",
    "    if remainder==0: return \"Sunday\"\n",
    "    elif remainder==1: return \"Monday\"\n",
    "    elif remainder==2: return \"Tuesday\"\n",
    "    elif remainder==3: return \"Wednesday\"\n",
    "    elif remainder==4: return \"Thursday\"\n",
    "    elif remainder==5: return \"Friday\"\n",
    "    elif remainder==6: return \"Saturday\"\n",
    "    else: return \"ERROR\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Friday'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calculate_day(2019,1,11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "13d8549943e343029109133bc9bb20c3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=1950, description='year', max=2019, min=1900), IntSlider(value=1, descri…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.calculate_day(year, month, day)>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from __future__ import print_function\n",
    "from ipywidgets import interact, interactive, fixed, interact_manual\n",
    "import ipywidgets as widgets\n",
    "\n",
    "interact(calculate_day, year=widgets.IntSlider(min=1900, max=2019, step=1, value=1950), month=widgets.IntSlider(min=1, max=12, step=1, value=1), day=widgets.IntSlider(min=1, max=31, step=1, value=1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](https://github.com/callysto/callysto-sample-notebooks/blob/master/notebooks/images/Callysto_Notebook-Banners_Bottom_06.06.18.jpg?raw=true)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
